package com.cnswhy.cloud.server.core.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cnswhy.cloud.common.core.base.entity.Entity;
import com.cnswhy.cloud.server.common.entity.enumeration.ExpressCompany;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;
import static com.cnswhy.cloud.common.core.utils.DateUtils.DEFAULT_DATE_TIME_FORMAT;

/**
 * <p>
 * 实体类
 * 商品订单表
 * </p>
 *
 * @author cnswhy
 * @since 2020-10-25
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_shop_order")
@ApiModel(value = "ShopOrder", description = "商品订单表")
@AllArgsConstructor
public class ShopOrder extends Entity<Long> {

    private static final long serialVersionUID = 1L;

    /**
     * 订单编号
     */
    @ApiModelProperty(value = "订单编号")
    @NotEmpty(message = "订单编号不能为空")
    @Length(max = 50, message = "订单编号长度不能超过50")
    @TableField(value = "order_no", condition = LIKE)
    @Excel(name = "订单编号")
    private String orderNo;

    /**
     * 买家id
     */
    @ApiModelProperty(value = "买家id")
    @NotNull(message = "买家id不能为空")
    @TableField("customer_id")
    @Excel(name = "买家id")
    private Long customerId;

    /**
     * 商户id
     */
    @ApiModelProperty(value = "商户id")
    @NotNull(message = "商户id不能为空")
    @TableField("merchant_id")
    @Excel(name = "商户id")
    private Long merchantId;

    /**
     * 支付类型 1-微信支付 2-支付宝3积分支付4拼购券支付5购物券支付
     */
    @ApiModelProperty(value = "支付类型 1-微信支付 2-支付宝3积分支付4拼购券支付5购物券支付")
    @NotNull(message = "支付类型 1-微信支付 2-支付宝3积分支付4拼购券支付5购物券支付不能为空")
    @TableField("pay_type")
    @Excel(name = "支付类型 1-微信支付 2-支付宝3积分支付4拼购券支付5购物券支付")
    private Integer payType;

    /**
     * 订单总金额
     */
    @ApiModelProperty(value = "订单总金额")
    @NotNull(message = "订单总金额不能为空")
    @TableField("order_price")
    @Excel(name = "订单总金额")
    private BigDecimal orderPrice;

    /**
     * 运费
     */
    @ApiModelProperty(value = "运费")
    @TableField("freight_price")
    @Excel(name = "运费")
    private BigDecimal freightPrice;

    /**
     * 抵扣积分
     */
    @ApiModelProperty(value = "抵扣积分")
    @TableField("deduction_integral")
    @Excel(name = "抵扣积分")
    private Integer deductionIntegral;

    /**
     * 状态：1-待付款 2-待发货 3-待收货 4-待评价 5-已完成 6-已取消 7-已关闭 8-退款中 9-拒绝退款 10-已退款 11-已删除
     */
    @ApiModelProperty(value = "状态：1-待付款 2-待发货 3-待收货 4-待评价 5-已完成 6-已取消 7-已关闭 8-退款中 9-拒绝退款 10-已退款 11-已删除")
    @TableField("status")
    @Excel(name = "状态：1-待付款 2-待发货 3-待收货 4-待评价 5-已完成 6-已取消 7-已关闭 8-退款中 9-拒绝退款 10-已退款 11-已删除")
    private Integer status;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    @Length(max = 500, message = "备注长度不能超过500")
    @TableField(value = "remark", condition = LIKE)
    @Excel(name = "备注")
    private String remark;

    /**
     * 退款单所属支付单id
     */
    @ApiModelProperty(value = "退款单所属支付单id")
    @TableField("pay_order_id")
    @Excel(name = "退款单所属支付单id")
    private Long payOrderId;

    /**
     * 付款时间
     */
    @ApiModelProperty(value = "付款时间")
    @TableField("pay_time")
    @Excel(name = "付款时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime payTime;

    /**
     * 支付订单号
     */
    @ApiModelProperty(value = "支付订单号")
    @Length(max = 50, message = "支付订单号长度不能超过50")
    @TableField(value = "pay_order_no", condition = LIKE)
    @Excel(name = "支付订单号")
    private String payOrderNo;

    /**
     * 通道返回订单号
     */
    @ApiModelProperty(value = "通道返回订单号")
    @Length(max = 50, message = "通道返回订单号长度不能超过50")
    @TableField(value = "return_order_no", condition = LIKE)
    @Excel(name = "通道返回订单号")
    private String returnOrderNo;

    /**
     * 支付说明
     */
    @ApiModelProperty(value = "支付说明")
    @Length(max = 200, message = "支付说明长度不能超过200")
    @TableField(value = "pay_msg", condition = LIKE)
    @Excel(name = "支付说明")
    private String payMsg;

    /**
     * 发货时间
     */
    @ApiModelProperty(value = "发货时间")
    @TableField("send_time")
    @Excel(name = "发货时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime sendTime;

    /**
     * 收货时间
     */
    @ApiModelProperty(value = "收货时间")
    @TableField("receive_time")
    @Excel(name = "收货时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime receiveTime;

    /**
     * 完成时间
     */
    @ApiModelProperty(value = "完成时间")
    @TableField("finish_time")
    @Excel(name = "完成时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime finishTime;

    /**
     * 取消原因
     */
    @ApiModelProperty(value = "取消原因")
    @Length(max = 255, message = "取消原因长度不能超过255")
    @TableField(value = "cancel_desc", condition = LIKE)
    @Excel(name = "取消原因")
    private String cancelDesc;

    /**
     * 申请退款原因
     */
    @ApiModelProperty(value = "申请退款原因")
    @Length(max = 500, message = "申请退款原因长度不能超过500")
    @TableField(value = "refund_apply_desc", condition = LIKE)
    @Excel(name = "申请退款原因")
    private String refundApplyDesc;

    /**
     * 申请退款时间
     */
    @ApiModelProperty(value = "申请退款时间")
    @TableField("refund_apply_time")
    @Excel(name = "申请退款时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime refundApplyTime;

    /**
     * 退款审核说明
     */
    @ApiModelProperty(value = "退款审核说明")
    @Length(max = 500, message = "退款审核说明长度不能超过500")
    @TableField(value = "refund_verify_desc", condition = LIKE)
    @Excel(name = "退款审核说明")
    private String refundVerifyDesc;

    /**
     * 退款审核时间
     */
    @ApiModelProperty(value = "退款审核时间")
    @TableField("refund_verify_time")
    @Excel(name = "退款审核时间", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime refundVerifyTime;

    /**
     * 订单是否已完结（完成时间超过最大退款天数）
     */
    @ApiModelProperty(value = "订单是否已完结（完成时间超过最大退款天数）")
    @NotNull(message = "订单是否已完结（完成时间超过最大退款天数）不能为空")
    @TableField("is_end")
    @Excel(name = "订单是否已完结（完成时间超过最大退款天数）")
    private Integer isEnd;

    /**
     * 快递单号
     */
    @ApiModelProperty(value = "快递单号")
    @Length(max = 100, message = "快递单号长度不能超过100")
    @TableField(value = "express_number", condition = LIKE)
    @Excel(name = "快递单号")
    private String expressNumber;

    /**
     * 快递公司
     */
    @ApiModelProperty(value = "快递公司")
    @Length(max = 100, message = "快递公司长度不能超过100")
    @TableField(value = "express_company", condition = LIKE)
    @Excel(name = "快递公司")
    private ExpressCompany expressCompany;

    /**
     * 抵扣类型1购物券2批发券
     */
    @ApiModelProperty(value = "抵扣类型1购物券2批发券")
    @TableField("deduction_type")
    @Excel(name = "抵扣类型1购物券2批发券")
    private Integer deductionType;
    @TableField("channel_order_id")
    @Excel(name = "渠道订单号")
    private String channelOrderId;
   /* @TableField(exist = false)
    private List<ShopOrderDetail> detailList;*/
    @TableField(exist = false)
    private CustomerReceiver receiver;
    //private CustomerInvoice invoice;

    @TableField(exist = false)
    private ShopOrderReceiver shopOrderReceiver;
    @TableField(exist = false)
    private Customer customer;
    @TableField(exist = false)
    private List<ShopOrderDetail> shopOrderDetails;

    @Builder
    public ShopOrder(Long id, LocalDateTime createTime, LocalDateTime updateTime, Long createUser, Long updateUser, 
                    String orderNo, Long customerId, Long merchantId, Integer payType, BigDecimal orderPrice, 
                    BigDecimal freightPrice, Integer deductionIntegral, Integer status, String remark, Long payOrderId, LocalDateTime payTime, 
                    String payOrderNo, String returnOrderNo, String payMsg, LocalDateTime sendTime, LocalDateTime receiveTime, LocalDateTime finishTime, 
                    String cancelDesc, String refundApplyDesc, LocalDateTime refundApplyTime, String refundVerifyDesc, LocalDateTime refundVerifyTime, Integer isEnd, 
                    String expressNumber, ExpressCompany expressCompany, Integer deductionType, String channelOrderId) {
        this.id = id;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.createUser = createUser;
        this.updateUser = updateUser;
        this.orderNo = orderNo;
        this.customerId = customerId;
        this.merchantId = merchantId;
        this.payType = payType;
        this.orderPrice = orderPrice;
        this.freightPrice = freightPrice;
        this.deductionIntegral = deductionIntegral;
        this.status = status;
        this.remark = remark;
        this.payOrderId = payOrderId;
        this.payTime = payTime;
        this.payOrderNo = payOrderNo;
        this.returnOrderNo = returnOrderNo;
        this.payMsg = payMsg;
        this.sendTime = sendTime;
        this.receiveTime = receiveTime;
        this.finishTime = finishTime;
        this.cancelDesc = cancelDesc;
        this.refundApplyDesc = refundApplyDesc;
        this.refundApplyTime = refundApplyTime;
        this.refundVerifyDesc = refundVerifyDesc;
        this.refundVerifyTime = refundVerifyTime;
        this.isEnd = isEnd;
        this.expressNumber = expressNumber;
        this.expressCompany = expressCompany;
        this.deductionType = deductionType;
        this.channelOrderId = channelOrderId;
    }

}
